import  React, { Fragment, useRef } from 'react'
import PubSub from 'pubsub-js';

export default function Input () {
  // const [iptVal, setIptVal] = useState('') 
  const iptValNode = useRef()
  function add (){
   // 获取input的值
  //  console.log(iptValNode.current.value)
    PubSub.publish('addItem', iptValNode.current.value)
    iptValNode.current.value = ''
  }
  return (
  <Fragment>
    <input ref = { iptValNode } />
    <button onClick={add} >Add</button>
  </Fragment>
  )
}